package com.gwtgeo.ui.server.handler;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.springframework.beans.factory.annotation.Autowired;

import com.google.inject.Inject;
import com.gwtgeo.service.manager.LocationManager;
import com.gwtgeo.ui.server.spring.ActionHandlerBean;
import com.gwtgeo.ui.shared.rpc.Search;
import com.gwtgeo.ui.shared.rpc.SearchResult;

@ActionHandlerBean
public class SearchHandler implements ActionHandler<Search,SearchResult>{
	
	@Autowired
	private LocationManager locationManager;
	
	@Inject
	public SearchHandler() {
		super();
	}

	@Override
	public SearchResult execute(Search action, ExecutionContext context)
			throws ActionException {
		return new SearchResult(locationManager.findByName(action.getText()));
	}

	@Override
	public Class<Search> getActionType() {
		return Search.class;
	}

	@Override
	public void rollback(Search search, SearchResult action, ExecutionContext context)
			throws ActionException {
		// TODO PMA20100207 Handle failure.
	}

	public void setLocationManager(LocationManager locationManager) {
		this.locationManager = locationManager;
	}
}
